import pysam
#from deepsignal3.utils import bam_reader


input_bam = "/public/data/hpc174601028/xiaoyf/human_5khz/20230429_1600_2E_PAO83395_124388f5/test1.dorado.5khz.5mc_5hmc.sup.sort.bam"
output_txt = "/public/data/hpc174601028/nipeng/human/workspace/ont_r1041_5khz_HG002/rockfish.inference.HG002_test1/bam.unique_readids.txt"


seen_read_ids = set()
#bam_index=bam_reader.ReadIndexedBam(input_bam)

with open(output_txt, "w") as output_file:
    
    with pysam.AlignmentFile(input_bam, "rb") as bam_file:
        
        for read in bam_file:
            read_id = read.query_name
            
            if read_id not in seen_read_ids:
                
                output_file.write(f"{read_id}\n")
                seen_read_ids.add(read_id)

print(f"Unique read IDs have been saved to {output_txt}")
